package ru.jexp.rcp.supply.swtext;

import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.TreeItem;

public class JExpTreeSelectMouseListener extends JExpMouseAdapter
{
	private TreeViewer viewer;

	public JExpTreeSelectMouseListener(TreeViewer viewer)
	{
		this.viewer = viewer;
	}

	@Override
	public void mouseUpRight(MouseEvent e)
	{
		TreeItem item = viewer.getTree().getItem(new Point(e.x, e.y));

		if (item != null)
		{
			viewer.getTree().setSelection(item);
		}
		else
		{
			viewer.getTree().deselectAll();
			viewer.setSelection(new StructuredSelection());
		}
	}
}
